<template>
  <div class="content">
    <div style="margin-top: 5rem;">
      <h3>{{ $route.meta.title }}</h3>
      <el-divider />
    </div>
    <div>
      <div class="box">
        <div class="boxtitle">当前环数：{{ params.loopNumber }}  &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          &nbsp; &nbsp;&nbsp;&nbsp;
          上涨次数：{{ params.roseRingNum }}
        </div>
        <!-- <div>{{params.loopNumber<100}}</div> -->
        <div v-show="params.loopNumber==100&&params.nodeNumber!=0" class="boxtitle">当环分币量：{{ params.loopCoinNumber }}USDT</div>
        <div v-show="params.loopNumber==100&& params.nodeNumber!=0"class="boxtitle">倒计时时间：{{ overtime }}</div>
        <div v-show="params.loopNumber>100" class="boxtitle">当环分币量：{{ params.loopCoinNumber }}USDT</div>
        <div v-show="params.loopNumber>100"class="boxtitle">倒计时时间：{{ overtime }}</div>
      </div>
      <div class="box">
        <div class="boxtitle">
          上涨环数：
        </div>
        <div class="boxtitle">
          当前节点数量：{{ params.nodeNumber }} &nbsp;&nbsp;&nbsp;&nbsp;
          <el-button type="primary" @click="open">增加</el-button>
          <!-- <el-button @click='dudu' type="primary" >111</el-button> -->
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { getInfo, addNode } from '@/api/jackbo/game.js'
export default {
  name: 'Nodeamount',
  data() {
    return {
      dudu1: '',
      overtime: '',
      params: {
        lastDate: '',
        loopCoinNumber: '',
        nodeNumber: '',
        loopNumber: ''
      }
    }
  },
  mounted() {
    this.getlist()
    // this.dudu()
    const that = this
    this.dudu1 = setInterval(() => {
      // 给他一个定时器，让他开始倒计时
      that.overtime = that.getCountDown(that.params.lastDate)
      //  console.log(aa)
    }, 1000)
  },
  beforeDestroy() {
    console.log(this.dudu1)
    clearInterval(this.dudu1)
  },
  methods: {
    getCountDown(min) {
      const that = this
      var nowT = new Date().getTime() // 获取现在时间的毫秒数
      var futureT = min + 172800000 // 获取未来时间的毫秒数
      // console.log(nowT, futureT);
      // console.log(new Date(nowT))
      // console.log(new Date(futureT))

      if (futureT < nowT) {
        // clearInterval(that.dudu1)
        return '到期了' // 因为是倒计时，所以必须判断未来时间大于现在时间
      }
      var mistiming = futureT - nowT // 获取时间差
      // console.log(mistiming);

      // 现在求这个时间差里有几天 时 分 秒；
      var day = Math.floor(mistiming / 1000 / 60 / 60 / 24) // 获取时间差里剩余的天数
      var hours = Math.floor((mistiming / 1000 / 60 / 60) % 48) // 获取时间差里剩余的小时数
      var minutes = Math.floor((mistiming / 1000 / 60) % 60) // 获取时间差里剩余的分钟数
      var seconds = Math.floor((mistiming / 1000) % 60) // 获取时间差里剩余的秒数
      // console.log(day, hours, minutes, seconds)
      // return ` ${day < 10 ? '0' + day : day}天${hours < 10 ? '0' + hours : hours}时${minutes < 10 ? '0' + minutes : minutes}分${seconds < 10 ? '0' + seconds : seconds}秒`//不足两位数的前面补0
      return `${hours < 10 ? '0' + hours : hours}时${
        minutes < 10 ? '0' + minutes : minutes
      }分${seconds < 10 ? '0' + seconds : seconds}秒` // 不足两位数的前面补0
    },
    dudu() {
      const that = this
      this.dudu1 = setInterval(() => {
        // 给他一个定时器，让他开始倒计时
        that.overtime = that.getCountDown(that.params.lastDate)
        //  console.log(aa)
      }, 1000)
    },

    open() {
      this.$confirm('确定要增加节点吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.determine()
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    getBit(value, bit = 3) {
      let str = value.toString()
      const strIndex = str.indexOf('.')
      if (strIndex === -1) return str
      str = str.substring(0, strIndex + bit)
      console.log(str, bit)
      return str
    },

    async getlist() {
      const res = await getInfo()
      if (res.code == 0) {
        // for (let key in res.data) {
        //   res.data[key] = this.getBit(res.data[key])
        // }
        console.log(res.data)
        this.params = res.data
      }
    },
    async determine() {
      const res = await addNode()
      if (res.code == 0) {
        this.getlist()
        this.$message({
          type: 'success',
          message: '增加成功!'
        })
      }

      // console.log(obj)
    }
  }
}
</script>
<style scoped>
.box {
  /* height:8rem; */
  padding: 1rem;
  border: 1px solid #dddddd;
  border-radius: 0.5rem;
  width: 98%;
  margin: 0 auto;
  /* border; */
  margin-top: 2rem;
}
.boxtitle {
  font-size: 1.25rem;
  height: 3rem;
  line-height: 3rem;
}
.int {
  display: inline-block;
  width: 10rem;
}
.boxcontent {
  font-size: 1.25rem;
  height: 3rem;
  line-height: 3rem;
}
</style>
